/*
 *
 * Copyright (c) 2023 - future
 * @author fzh
 * @email e_341877120_mail@163.com
 * @link https://mvnrepository.com/search?q=io.github.xrfzh.cn
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package cn.xrfzh.log.controller;

import cn.xrfzh.common.annotation.SystemLog;
import cn.xrfzh.common.axios.AxiosEnum;
import cn.xrfzh.common.axios.AxiosResult;
import cn.xrfzh.common.entity.dto.OperationLogDto;
import cn.xrfzh.common.enums.LogType;
import cn.xrfzh.log.service.IOperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 操作日志表
 *
 * @author fzh
 * @email e_341877120_mail@163.com
 * @date 2023-03-30 18:28:23
 */
@RestController
@RequestMapping("/api/v1/log/operationLog")
public class OperationLogController {

	@Autowired
	private IOperationLogService iOperationLogService;

	/**
	 * 根据条件查询列表
	 * @param operationLogDto
	 * @return
	 */
	@ApiOperation(tags = "查询", value = "查询OperationLog信息")
	@GetMapping("/selectList")
	public AxiosResult selectList(OperationLogDto operationLogDto) {
		return iOperationLogService.selectList(operationLogDto);
	}

	/**
	 * 根据条件分页查询
	 * @param currentPage
	 * @param pageSize
	 * @param operationLogDto
	 * @return
	 */
	@ApiOperation(tags = "查询", value = "分页查询OperationLog信息")
	@GetMapping("/selectPage/{currentPage}/{pageSize}")
	public AxiosResult selectPage(@PathVariable int currentPage, @PathVariable int pageSize,
			OperationLogDto operationLogDto) {
		return iOperationLogService.selectPage(currentPage, pageSize, operationLogDto);
	}

	/**
	 * 根据id查询单个
	 * @param id
	 * @return
	 */
	@ApiOperation(tags = "查询", value = "根据id查询OperationLog信息")
	@GetMapping("/selectOneById/{id}")
	public AxiosResult selectOneById(@PathVariable Long id) {
		return iOperationLogService.selectOneById(id);
	}

	/**
	 * 新增
	 * @param operationLogDto
	 * @return
	 */
	@ApiOperation(tags = "新增", value = "新增OperationLog信息")
	@PostMapping("/insert")
	public AxiosResult insert(@RequestBody OperationLogDto operationLogDto) {
		return iOperationLogService.insert(operationLogDto);
	}

	/**
	 * 更新
	 * @param operationLogDto
	 * @return
	 */
	@ApiOperation(tags = "更新", value = "更新OperationLog信息")
	@PutMapping("/update")
	public AxiosResult update(@RequestBody OperationLogDto operationLogDto) {
		return iOperationLogService.update(operationLogDto);
	}

	/**
	 * 根据id删除单个
	 * @param id
	 * @return
	 */
	@SystemLog(module = "日志模块", type = LogType.DELETE, description = "删除OperationLog信息")
	@ApiOperation(tags = "删除", value = "删除OperationLog信息")
	@DeleteMapping("/delete/{id}")
	public AxiosResult delete(@PathVariable Long id) {
		return iOperationLogService.delete(id);
	}

	/**
	 * 根据id集合批量删除
	 * @param idList
	 * @return
	 */
	@SystemLog(module = "日志模块", type = LogType.DELETE, description = "批量删除OperationLog信息")
	@ApiOperation(tags = "删除", value = "批量删除OperationLog信息")
	@PostMapping("/deleteBatch")
	public AxiosResult deleteBatch(@RequestBody List<Long> idList) {
		return iOperationLogService.deleteBatch(idList);
	}

	/**
	 * 导入文件
	 * @param file
	 * @return
	 */
	@ApiOperation(tags = "导入", value = "导入OperationLog信息")
	@PostMapping("/importFile")
	public AxiosResult importFile(@RequestBody MultipartFile file) {
		return iOperationLogService.importFile(file);
	}

	/**
	 * 导出文件
	 * @param response
	 */
	@SystemLog(module = "日志模块", type = LogType.EXPORT, description = "导出OperationLog信息")
	@ApiOperation(tags = "导出", value = "导出OperationLog信息")
	@GetMapping("/exportFile")
	public AxiosResult exportFile(HttpServletResponse response) {
		iOperationLogService.exportFile(response);
		return AxiosResult.success(AxiosEnum.EXPORT_SUCCESS);
	}

}
